package com.sunnyatwal.kettlebell.clock.display;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat.Builder;

import com.sunnyatwal.kettlebell.ClockActivity;
import com.sunnyatwal.kettlebell.R;
import com.sunnyatwal.kettlebell.model.Exercise;
import com.sunnyatwal.kettlebell.model.SubExercise;

public class ClockNotification implements KettlebellDisplay {

	private int NOTIFICATION = R.string.string_clock_service;
	
	private NotificationManager mNotif;
	private Context mContext;
	
	
	public ClockNotification(NotificationManager notif, Context c) {
		mNotif = notif;
		mContext = c;
	}
	
	
	@Override
	public void ToDisplay(Exercise exercise) {
		
		Intent intent = new Intent(mContext, ClockActivity.class);
		PendingIntent pIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
		
		Builder mBuilder = new Builder(mContext);
		
		try {
			
			if(exercise.isFinished()) {
				mBuilder
				.setSmallIcon(R.drawable.logo_small)
				.setContentTitle(mContext.getString(R.string.string_done))
				.setContentIntent(pIntent);
			}
			else {
			
				mBuilder
				.setSmallIcon(R.drawable.logo_small)
				.setContentTitle(exercise.getPrettyNotificationMainText())
				.setContentText(exercise.getPrettyNotificationSubText())
				.setContentIntent(pIntent);
				
				if(exercise.getCurrentExercise() instanceof SubExercise) {
					SubExercise s = (SubExercise) exercise.getCurrentExercise();
					mBuilder.setProgress(100, s.getCurrentRepCompleted(), false);
				}
				else {
					mBuilder.setProgress(100, 100, false);
				}				
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		mNotif.notify(NOTIFICATION, mBuilder.build());
	}

	
	@Override
	public void Reset() {
		mNotif.cancel(NOTIFICATION);
	}

	
	@Override
	public void Done() {
	}

	
}
